package com.mobzilla.activity;

import java.util.List;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.mobzilla.model.Bug;

public final class BugListActivity extends ListActivity implements OnItemClickListener
{
	static List<Bug> bugList = null;
	
	public static void setBugList(List<Bug> bgList)
	{
		bugList = bgList;
	}
	
	public String[] bugListToStringList()
	{
		int size = bugList.size();
		String s[] = new String[size];
		Bug b = null;
		for(int i=0; i<size; i++)
		{
			b = bugList.get(i);
			s[i] = "Bug #" + b.getId().toString() + " " + b.getSummary();
		}
		return s;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);

		setListAdapter(new ArrayAdapter<String>(this, R.layout.buglist, bugListToStringList()));
		ListView lv = getListView();
		lv.setTextFilterEnabled(true);
		lv.setOnItemClickListener(this);
	}
	
	public void onItemClick(AdapterView<?> parent, View view, int position, long id)
	{
		BugDetailsViewActivity.setBug(bugList.get(position));
		
		Intent i = new Intent(this, BugDetailsViewActivity.class);
		
		startActivity(i);
		
		//Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
	}
	
}
